package com.bookstore.controller;

import com.bookstore.common.Result;
import com.bookstore.entity.Favorite;
import com.bookstore.service.FavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/favorite")
@Api(tags = "收藏管理接口")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @PostMapping
    @ApiOperation("添加收藏")
    public Result<Boolean> addFavorite(@RequestBody Favorite favorite) {
        return Result.success(favoriteService.addFavorite(favorite));
    }

    @DeleteMapping("/{favoriteId}")
    @ApiOperation("取消收藏")
    public Result<Boolean> removeFavorite(
            @ApiParam("收藏ID") @PathVariable Integer favoriteId) {
        return Result.success(favoriteService.removeFavorite(favoriteId));
    }

    @PutMapping("/{favoriteId}/remark")
    @ApiOperation("更新收藏备注")
    public Result<Boolean> updateRemark(
            @ApiParam("收藏ID") @PathVariable Integer favoriteId,
            @ApiParam("备注") @RequestParam String remark) {
        return Result.success(favoriteService.updateRemark(favoriteId, remark));
    }

    @GetMapping("/user/{userId}")
    @ApiOperation("获取用户收藏列表")
    public Result<List<Favorite>> getUserFavorites(
            @ApiParam("用户ID") @PathVariable Integer userId) {
        return Result.success(favoriteService.getUserFavorites(userId));
    }

    @GetMapping("/check")
    @ApiOperation("检查是否已收藏")
    public Result<Boolean> isFavorite(
            @ApiParam("用户ID") @RequestParam Integer userId,
            @ApiParam("图书ID") @RequestParam Integer bookId) {
        return Result.success(favoriteService.isFavorite(userId, bookId));
    }
} 